package com.suixingfu.utils;

import java.io.ByteArrayOutputStream;

public class PublicPartUtils {

	//公共url
//	public static String url = "http://106.37.197.53:38080/";
	public static String url2 = "http://106.37.197.53:38080/";
	public static String url = "http://dpay.suixingpay.com:38080/";
	
	// 合作商私钥签名
//	public static String RSAKey="MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMsQ9C0MDJ8uJO2CNMHDxpyo3/M5dCWD273HYR3BvqtOGZ8/LBf6ARrY99hHbxTtBIDjMeT6H8NhL20T6jdtXH0nQVGPBTjYTcw+gNYAZZiQNaLfh1P9UKkRKi7REefGIeqhy7OFkTL9LkwljyVepVQLud8et8XNE4rOHKo+2QlzAgMBAAECgYBp+lgk5mPz82YsWkbkVSNjgTMXwgVeytk0y0hg+ktjJehzVsnRXZWUCGYZBvbvKd+u0GOqx+sp0Z+pwrn64WVhsU/hw7YTBEwmuH7bl+xPLj7oU8ErWQvbuYMTHhFiJCw+DpWAUtYzyBir8Ba0G5sqbKawNfrKU/pIvr3vKI+GaQJBAPMcwRCP6MNoj7Y4boy+wqF7zTPIip0x6ylADPm/nrQqz77FJf5y3rrmm6Rj88UpLPetjB5/seUacUtcj9dSYXUCQQDV1L1Bc5QR8A8poG5oHlQZLblMf5mN0BJUsQqfVuT69E++x8d26ueKgv+HsrXvQ+1bhNgiVZw0Zwek/tNsTbpHAkAX1IG4NeMDBITRv8ZWVXyOh6wdn1K3BeWfLYAYGwhbcLbcZEbNIkVi3Kf0/Tcv5FFcFc7eTnYJlwXz9SbEXHbhAkEAsW6G4EG0kzHckxEBrDnGVOJBCP40f50xKL+DbfZfqPGDHm6Nz9pZ6PCMcqBTIUf/M9rGsa7SIBWCHWIqM4tHzwJBAL/kwKeHzsWVXQbrWDhUwVoLam3TCAYE0f6PXJgcdAx3rQYGPwDbuv6pWZZZ91I6ZcmEIqMaNx7YnxyA2VRvmvY=";
	public static String RSAKey="MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIHemzNud4PTdIaNmrVjB33o+T2a74JChAg0LtVE+cCfOOxYIYF891lAjX13QZCJRnlvDvGb9REAhea2AG1DkZ+p8Gxo9NjDD+yXCrqud4ZTY9FJKinhN6rvamd8wccrXHlB8JzJ3hWTSdkSr4Kenu0fdNkDGfuIxYpaoXH5AbgvAgMBAAECgYAfWWkFhUj8XXLneA88cedBEZf4swnV29CbWl1jxf6z7LuE8dFEvLHIrbh57Ou6xChq79AfqpIBxKqOAqkftwvTstZJnzuEZLO+rrJW4mebX5ou1TcTgREOw0cMRC49mJgg0wgbllHdCjBsx1XgjXnXNbGUfdpfRqIrfMarLEdogQJBALtICcnKxb8b9fbiI/YDOH1xkWemNfPDz3N9dGuJkrShjRvzsqJlPgGO7Py4d4EkOfJuzpBfyuiVds/+LRg/oVECQQCxha759aaHBnxQhr4gwX76KzxUotEJZ/M74U5IIhqXY9cPgx5Zvgv/jNo5hcVZP9nTfeHO2pm6YRshvkL0AWF/AkBUSf/dyl1lvffdvbnhp2FtVAfVVoFBzQc5O2WCYNCea3dO9UeYv2hA20reE0f135AVBLoDUJnKRDrNMeCp4TmBAkAWy/QMZV9dN5f/P05rJm4H8kVtGPt/GbpClkxXNwnzJv8XHt9m5uDjkFL10Bfnvita3W+CANB8/rtdOfGfJA5BAkEAi8GsT7DgQcrk4qu7LHo4EQbaLAH2ZaFrZ5HFW5UYn11fgV41tLShbA1MnBROYSpsKJ80bT49gvoomgbLJJRd7g==";
	
	// 验证签名，随行付公钥
	public static String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDBJueJs8wh//LEvrMDKpb5Dcxaa8e3C9YtLzX8rxigm5cENlFlHMQRZtYfM900AhpH+1gsNz9/0zVCODrTjUyU+zSqqGvkY6igOhgX2UrTdByF7mIXeCWsrrRIirjsOUzmzR5AGMe8bk8AS5inzZYDaLWLulwwJDar2dy9gWgQwIDAQAB";
	
	// DES密钥加密
	public static String DESkey = "12345678";
	
	private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D',
            'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
            'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
            'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
            'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
            '4', '5', '6', '7', '8', '9', '+', '/', };

private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
            -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59,
            60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,
            -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
            38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1,
            -1, -1 };

/**
* 解密
* @param str
* @return
*/
public static byte[] decode(String str) {
    byte[] data = str.getBytes();
    int len = data.length;
    ByteArrayOutputStream buf = new ByteArrayOutputStream(len);
    int i = 0;
    int b1, b2, b3, b4;

    while (i < len) {
            do {
                    b1 = base64DecodeChars[data[i++]];
            } while (i < len && b1 == -1);
            if (b1 == -1) {
                    break;
            }

            do {
                    b2 = base64DecodeChars[data[i++]];
            } while (i < len && b2 == -1);
            if (b2 == -1) {
                    break;
            }
            buf.write((int) ((b1 << 2) | ((b2 & 0x30) >>> 4)));

            do {
                    b3 = data[i++];
                    if (b3 == 61) {
                            return buf.toByteArray();
                    }
                    b3 = base64DecodeChars[b3];
            } while (i < len && b3 == -1);
            if (b3 == -1) {
                    break;
            }
            buf.write((int) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));

            do {
                    b4 = data[i++];
                    if (b4 == 61) {
                            return buf.toByteArray();
                    }
                    b4 = base64DecodeChars[b4];
            } while (i < len && b4 == -1);
            if (b4 == -1) {
                    break;
            }
            buf.write((int) (((b3 & 0x03) << 6) | b4));
    }
    return buf.toByteArray();
}

}
